package arraytest;
/*
    数组元素求和
    int sum = 0;
 */
public class ArrayTest1 {
    public static void main(String[] args) {
        //静态初始化一个数组
        int[] arr = {1,2,3,4,5};
        //求和变量
        int sum = 0;
        //遍历数组,取出数组中每一个元素值
        for (int i = 0; i < arr.length; i++) {
            //取数
            int num = arr[i];
            //累加
            sum +=num;
        }
        System.out.println("sum = " + sum);
    }
}
